package com.heiyu.task;

import com.heiyu.dao.MessageInfoMapper;
import com.heiyu.entity.MessageInfo;
import com.heiyu.utils.HttpUtil;
import com.heiyu.utils.Md5Utils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SendMsgTask {

    @Autowired
    private MessageInfoMapper messageInfoMapper;

    @Scheduled(fixedDelay = 2000)
    public void execute(){
        MessageInfo info = new MessageInfo();
        info.setStatus("0");
       List<MessageInfo> list = messageInfoMapper.selectList(info);
       if(CollectionUtils.isNotEmpty(list)){
           for(MessageInfo messageInfo:list){
               messageInfo.setStatus("9");
               this.messageInfoMapper.updateById(messageInfo);
               if(messageInfo.getToTelphone().startsWith("17")){
                   HttpUtil.doGet("http://sms.smspaas.com/mt.php?appId=10345&modeId=211227&vars="+messageInfo.getParams()+"&mobile="+messageInfo.getToTelphone()+"&sign="+Md5Utils.md5("58d246d33010345"+messageInfo.getToTelphone()).toLowerCase(),"UTF-8");
               }else
               HttpUtil.doGet("http://sms.smspaas.com/mt.php?appId=10345&modeId=206682&vars="+messageInfo.getParams()+"&mobile="+messageInfo.getToTelphone()+"&sign="+Md5Utils.md5("58d246d33010345"+messageInfo.getToTelphone()).toLowerCase(),"UTF-8");
           }
       }
    }
}
